from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-08 14:07:36.159983
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 08, Feb, 2022
Time: 14:07:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0302
Nobs: 561.000 HQIC: -48.4536
Log likelihood: 6593.10 FPE: 6.90368e-22
AIC: -48.7249 Det(Omega_mle): 5.88873e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351007 0.069131 5.077 0.000
L1.Burgenland 0.106203 0.042037 2.526 0.012
L1.Kärnten -0.110686 0.021836 -5.069 0.000
L1.Niederösterreich 0.193353 0.087452 2.211 0.027
L1.Oberösterreich 0.131725 0.086762 1.518 0.129
L1.Salzburg 0.254432 0.044462 5.723 0.000
L1.Steiermark 0.034767 0.058595 0.593 0.553
L1.Tirol 0.099370 0.047307 2.101 0.036
L1.Vorarlberg -0.070866 0.041810 -1.695 0.090
L1.Wien 0.018087 0.077154 0.234 0.815
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055392 0.149612 0.370 0.711
L1.Burgenland -0.040948 0.090976 -0.450 0.653
L1.Kärnten 0.041094 0.047257 0.870 0.385
L1.Niederösterreich -0.197953 0.189261 -1.046 0.296
L1.Oberösterreich 0.454868 0.187767 2.423 0.015
L1.Salzburg 0.283099 0.096222 2.942 0.003
L1.Steiermark 0.114203 0.126808 0.901 0.368
L1.Tirol 0.305373 0.102380 2.983 0.003
L1.Vorarlberg 0.022748 0.090483 0.251 0.802
L1.Wien -0.028128 0.166974 -0.168 0.866
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194686 0.035298 5.515 0.000
L1.Burgenland 0.089081 0.021464 4.150 0.000
L1.Kärnten -0.007344 0.011150 -0.659 0.510
L1.Niederösterreich 0.236637 0.044652 5.300 0.000
L1.Oberösterreich 0.169163 0.044300 3.819 0.000
L1.Salzburg 0.039128 0.022702 1.724 0.085
L1.Steiermark 0.025407 0.029918 0.849 0.396
L1.Tirol 0.081417 0.024155 3.371 0.001
L1.Vorarlberg 0.054865 0.021348 2.570 0.010
L1.Wien 0.118813 0.039394 3.016 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120172 0.035311 3.403 0.001
L1.Burgenland 0.043495 0.021472 2.026 0.043
L1.Kärnten -0.013511 0.011154 -1.211 0.226
L1.Niederösterreich 0.169566 0.044669 3.796 0.000
L1.Oberösterreich 0.334747 0.044317 7.553 0.000
L1.Salzburg 0.099604 0.022710 4.386 0.000
L1.Steiermark 0.110515 0.029929 3.693 0.000
L1.Tirol 0.090551 0.024164 3.747 0.000
L1.Vorarlberg 0.061041 0.021356 2.858 0.004
L1.Wien -0.016391 0.039409 -0.416 0.677
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125860 0.066556 1.891 0.059
L1.Burgenland -0.048507 0.040471 -1.199 0.231
L1.Kärnten -0.045560 0.021023 -2.167 0.030
L1.Niederösterreich 0.138057 0.084194 1.640 0.101
L1.Oberösterreich 0.164428 0.083530 1.969 0.049
L1.Salzburg 0.284346 0.042805 6.643 0.000
L1.Steiermark 0.057462 0.056412 1.019 0.308
L1.Tirol 0.156341 0.045545 3.433 0.001
L1.Vorarlberg 0.095297 0.040252 2.368 0.018
L1.Wien 0.075498 0.074280 1.016 0.309
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080758 0.051916 1.556 0.120
L1.Burgenland 0.024517 0.031569 0.777 0.437
L1.Kärnten 0.053352 0.016398 3.253 0.001
L1.Niederösterreich 0.191352 0.065674 2.914 0.004
L1.Oberösterreich 0.330845 0.065156 5.078 0.000
L1.Salzburg 0.032858 0.033389 0.984 0.325
L1.Steiermark 0.004597 0.044003 0.104 0.917
L1.Tirol 0.119686 0.035526 3.369 0.001
L1.Vorarlberg 0.066314 0.031398 2.112 0.035
L1.Wien 0.097723 0.057940 1.687 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172734 0.062731 2.754 0.006
L1.Burgenland 0.003158 0.038146 0.083 0.934
L1.Kärnten -0.065790 0.019815 -3.320 0.001
L1.Niederösterreich -0.112721 0.079356 -1.420 0.155
L1.Oberösterreich 0.212887 0.078730 2.704 0.007
L1.Salzburg 0.053396 0.040345 1.323 0.186
L1.Steiermark 0.249285 0.053170 4.688 0.000
L1.Tirol 0.499033 0.042927 11.625 0.000
L1.Vorarlberg 0.065947 0.037939 1.738 0.082
L1.Wien -0.074566 0.070011 -1.065 0.287
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158035 0.069410 2.277 0.023
L1.Burgenland -0.005185 0.042207 -0.123 0.902
L1.Kärnten 0.061642 0.021924 2.812 0.005
L1.Niederösterreich 0.173712 0.087805 1.978 0.048
L1.Oberösterreich -0.065796 0.087112 -0.755 0.450
L1.Salzburg 0.205986 0.044641 4.614 0.000
L1.Steiermark 0.139748 0.058831 2.375 0.018
L1.Tirol 0.057684 0.047498 1.214 0.225
L1.Vorarlberg 0.143927 0.041978 3.429 0.001
L1.Wien 0.133488 0.077465 1.723 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394342 0.040590 9.715 0.000
L1.Burgenland -0.003385 0.024682 -0.137 0.891
L1.Kärnten -0.021042 0.012821 -1.641 0.101
L1.Niederösterreich 0.199056 0.051347 3.877 0.000
L1.Oberösterreich 0.237085 0.050941 4.654 0.000
L1.Salzburg 0.034603 0.026105 1.326 0.185
L1.Steiermark -0.018800 0.034403 -0.546 0.585
L1.Tirol 0.088951 0.027776 3.202 0.001
L1.Vorarlberg 0.052535 0.024548 2.140 0.032
L1.Wien 0.039872 0.045300 0.880 0.379
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035254 0.104811 0.168723 0.134374 0.095787 0.081180 0.030438 0.212473
Kärnten 0.035254 1.000000 -0.024782 0.132642 0.046830 0.086102 0.444128 -0.068652 0.092058
Niederösterreich 0.104811 -0.024782 1.000000 0.309729 0.123295 0.268029 0.064852 0.156374 0.280249
Oberösterreich 0.168723 0.132642 0.309729 1.000000 0.215551 0.293910 0.169451 0.134074 0.236258
Salzburg 0.134374 0.046830 0.123295 0.215551 1.000000 0.124867 0.091119 0.103692 0.128265
Steiermark 0.095787 0.086102 0.268029 0.293910 0.124867 1.000000 0.134479 0.106179 0.029296
Tirol 0.081180 0.444128 0.064852 0.169451 0.091119 0.134479 1.000000 0.063658 0.152438
Vorarlberg 0.030438 -0.068652 0.156374 0.134074 0.103692 0.106179 0.063658 1.000000 -0.003036
Wien 0.212473 0.092058 0.280249 0.236258 0.128265 0.029296 0.152438 -0.003036 1.000000